package com.rocsun.dubbo.aspect;


import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;

/**
 * class:ProviderAspect create by @author gyxhp in 2023/4/16 22:35
 */
@Aspect
@Component
public class ProviderAspect {

    @Pointcut("execution(* com.rocsun.dubbo.service..*.*())")
    public void cutPoint() {}

    @Around("cutPoint()")
    public void doAround(ProceedingJoinPoint joinPoint){
        try {
            StopWatch stopWatch = new StopWatch();
            stopWatch.start();
            System.out.println("前置处理");
            joinPoint.proceed();
            stopWatch.stop();
            System.out.printf("后置处理，共计耗时：%s%n", stopWatch.getTotalTimeMillis());
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
    }

}
